Add convenience syntax to install current crate
authorGeorge Hilliard <gh403@msstate.edu>
Fri, 11 Dec 2015 07:18:11 +0000 (01:18 -0600)
committerGeorge Hilliard <gh403@msstate.edu>
Fri, 11 Dec 2015 18:35:15 +0000 (12:35 -0600)
Essentially, `cargo install` becomes a synonym for
`cargo install --path .`.  This makes it easy and intuitive to install
the crate in the current directory, as in the following:

    $ cargo build --release
    $ cargo install

Note that this only works from the crate root.

Closes #2142.

src/bin/install.rs
src/cargo/ops/cargo_install.rs

index 141956179f26f0e596a9794b46606f18138c7c74..3998111d9e9cc53fda3c628a9ca930b1df5e5eeb 100644 (file)
@@ -75,6 +75,10 @@ crate has multiple binaries, the `--bin` argument can selectively install only
 one of them, and if you'd rather install examples the `--example` argument can
 be used as well.
 
+As a special convenience, omitting the <crate> specification entirely will
+install the crate in the current directory. That is, `install` is equivalent to
+the more explicit `install --path .`.
+
 The `--list` option will list all installed packages (and their versions).
 ";
 
@@ -112,6 +116,8 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
         SourceId::for_git(&url, gitref)
     } else if let Some(path) = options.flag_path {
         try!(SourceId::for_path(&config.cwd().join(path)))
+    } else if options.arg_crate == None {
+        try!(SourceId::for_path(&config.cwd()))
     } else {
         try!(SourceId::for_central(config))
     };
index dc02233809e63b2e7176c6f968a2a9236019864d..1aa51627949b0712feaad34b1ae1e36ab16a9e08 100644 (file)
@@ -51,7 +51,11 @@ pub fn install(root: Option<&str>,
                             .expect("path sources must have a valid path");
         try!(select_pkg(PathSource::new(&path, source_id, config),
                         source_id, krate, vers,
-                        &mut |path| path.read_packages()))
+                        &mut |path| path.read_packages())
+                 .chain_error(|| human(format!("`{}` is not a crate root; specify a \
+                                                crate to install from crates.io, or \
+                                                use --path or --git to specify an \
+                                                alternate source", path.display()))))
     } else {
         try!(select_pkg(RegistrySource::new(source_id, config),
                         source_id, krate, vers,